Skip to content

Conversation

Jineshbansal
Copy link
Contributor

What was wrong?

This PR aims to make TProtocol as Optional[TProtocol] to keep types consistent in py-libp2p/libp2p/protocol_muxer/multiselect.py

@Jineshbansal
Copy link
Contributor Author

Jineshbansal commented Jul 15, 2025

Please take a look at this @seetadev , If you tell me some pointers on how to check its reliability, that would be really helpful. Currently I just change the TProtocol as Optional[TProtocol] and totally rely on tests ("tests/core/protocol_muxer/test_protocol_muxer.py", pre-commit tests) to make further changes.

@seetadev
Copy link
Contributor

@Jineshbansal : Great, thank you so much for sharing the PR. Appreciate it.

Definitely, I'll review it.

CCing @sumanjeet0012 and @acul71 for their feedback and review too.

@acul71
Copy link
Contributor

acul71 commented Jul 17, 2025

I've seen that windows test failing randomly in other PRs
FAILED tests/core/pubsub/test_gossipsub_px_and_backoff.py::test_peer_exchange

@Jineshbansal
Copy link
Contributor Author

@acul71 thanks for pointing it out, I will definitely look into this

@seetadev
Copy link
Contributor

@acul71 , @Jineshbansal : Not related, we can ignore this test case. CCing @mystical-prog, who could help fix it via a PR.

@Jineshbansal : Please add newsfragment and more test cases.

@acul71
Copy link
Contributor

acul71 commented Aug 12, 2025

@Jineshbansal @seetadev
What's the current status of this ? @Jineshbansal are you still woking on this?

@Jineshbansal
Copy link
Contributor Author

@acul71 , sorry I couldn't get a time for this, I will finalize my changes in this week

@Jineshbansal
Copy link
Contributor Author

Jineshbansal commented Aug 18, 2025

@acul71 PTAL

@seetadev
Copy link
Contributor

@Jineshbansal : Hi Jinesh. Please add some test cases to check the PR too. Thank you for adding the newsfragment.

@acul71
Copy link
Contributor

acul71 commented Aug 18, 2025

@acul71 PTAL

@Jineshbansal Thanks for the updates! I can see you've added the newsfragment and made the type annotation changes.

Great work on the implementation! I've reviewed the changes and here's my assessment:

✅ What's Working Well:

  • The type annotation fix correctly addresses the interface/implementation mismatch
  • All existing tests continue to pass (11/11)
  • The 4 new test cases provide good coverage for Optional[TProtocol] scenarios
  • The logic properly handles None values in protocol negotiation

🔍 Areas for Enhancement:

  1. Broader Type Consistency Check: Are there other places in the codebase where similar interface/implementation type mismatches might exist? I noticed several files already use TProtocol | None - it would be good to verify they're all consistent.

  2. Edge Case Testing: The new tests are good, but could we add a test that verifies the behavior when:

    • Empty string commands are received
    • Multiple None protocols are in the handlers dict
    • Protocol negotiation timeout scenarios

Overall Assessment:
This is a solid fix that improves type safety and consistency. The implementation is correct and the test coverage is adequate. With the suggested improvements, this PR would be ready for merge.

Thanks for addressing this type consistency issue!


## Action Items for @Jineshbansal
1. Add comprehensive test cases for Optional[TProtocol] behavior
2. Check for similar type annotation issues elsewhere in the codebase
3. Ensure all None cases are handled properly

## Timeline
- PR opened: July 15, 2025
- Last update: August 18, 2025
- Status: Awaiting test cases and final review

## Related Issues
- Addresses type annotation inconsistency in protocol muxer
- Improves type safety and consistency across the codebase

@Jineshbansal
Copy link
Contributor Author

@acul71 For now, I’m adding the unit test. I’ll check for similar type annotation issues elsewhere in the codebase later, as I have some other tasks to focus on right now. Could you please merge the PR?

@acul71
Copy link
Contributor

acul71 commented Aug 19, 2025

@acul71 For now, I’m adding the unit test. I’ll check for similar type annotation issues elsewhere in the codebase later, as I have some other tasks to focus on right now. Could you please merge the PR?

Well done @Jineshbansal
The added tests completes the PR
The PR successfully addresses a real type consistency issue, has comprehensive test coverage, and proves the functionality is actually used. The implementation is correct and safe to merge.
@seetadev Reviewed: Approved, ready to be Merged.

@pacrob pacrob merged commit dabb3a0 into libp2p:main Aug 20, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants